home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / ckdns / ckdns.shar / ckdomaincf.sh next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1996-10-25  |  2.8 KB  |  129 lines

  1. #!/bin/sh
  2. # @(#)ckdomaincf.sh    1.3    1/4/91
  3. #
  4. # ckdomaincf - check domain configuration
  5. #
  6. # SYNOPSIS
  7. #    ckdomaincf [ -n ]
  8. #
  9. # ckdomaincf checks the domain configuration.  It determines which
  10. # domains to check by examining /etc/named.boot and checking all domains
  11. # listed on the primary and secondar lines.  However, ckdomaincf ignores
  12. # checking the 0.0.127.in-addr.arpa domain and any domain with unixhosts
  13. # as the data file.  It is assumed that these domain data files will
  14. # contain domain definitions for the unix localhost and will be specific
  15. # to the local definition.
  16. # If the -n flag is specified, no mail will be sent after checking.
  17. BOOTFILE=/etc/named.boot
  18. MAIL=/usr/ucb/Mail
  19. NOTIFY=hostmaster
  20. NOTIFYLEVEL=10    # 10 - any warning or greater
  21.         # 50 - any error or greater
  22.         # 100 - any abort
  23. PATH=$PATH:/usr/local/etc export PATH
  24. TMP=/tmp/.ckd$$
  25.  
  26. set -- `getopt n $*`
  27. if [ $? != 0 ]; then
  28.     echo usage: ckdomaincf [ -n ]
  29.     exit 2
  30. fi
  31. for i in $*; do
  32.     case $i in
  33.     -n ) MAIL="echo /usr/ucb/Mail"; shift;;
  34.     --)     shift; break;;
  35.     esac
  36. done
  37.  
  38. tolower() {
  39.     echo $1 | tr A-Z a-z
  40. }
  41.  
  42. is_in_addr() {
  43.     if [ `expr $1 : '.*in-addr'` -gt 0 ]; then
  44.         true;
  45.     else
  46.         false;
  47.     fi
  48. }
  49.  
  50. # strip comments from zone data
  51. stripcomments() {
  52.         sed -e '/^;/d' -e 's/;.*//' $*
  53. }
  54.  
  55. # get mail address of person in charge of the zone
  56. getpersonincharge() {
  57.     dig soa $1. +pfset=0xa224 | \
  58.         stripcomments | tr a-z A-Z | awk '$3 == "SOA" {print $5}'
  59. }
  60.  
  61. # convert domain name to mail address
  62. domaintoaddr() {
  63.         echo $1 | sed -e 's/\.$//' -e 's/\./@/'
  64. }
  65.  
  66. # notify the person in charge of a zone of detected errors
  67. notifypersonincharge() {
  68.     failtype=problems
  69.     if [ $2 -gt 50 ]; then
  70.         failtype=errors
  71.     fi
  72.     if [ $2 -gt 100 ]; then
  73.         failtype=failures
  74.     fi
  75.         MB=`getpersonincharge $1`
  76.     ( cat $1.log;
  77.       echo ""; echo ""; echo ""; echo "Complete log of test follows:"; echo " ";
  78.       cat log.$1.
  79.     ) | \
  80.         $MAIL -s "$1 zone configuration $failtype" $NOTIFY `domaintoaddr $MB` 
  81.         echo $1 zone configuration $failtype
  82.     sed 's/^/  /' $1.log
  83.         echo "  $NOTIFY, `domaintoaddr $MB` notified via mail."
  84.     echo ""
  85. }
  86.  
  87. cd /tmp
  88.  
  89. trap "rm -f $TMP*; exit 1" 2 3
  90.  
  91. egrep '^(primary|secondary)' $BOOTFILE >$TMP.domains
  92.  
  93. while read line; do
  94.     set -- $line
  95.  
  96.     domainname=`tolower $2`
  97.     if is_in_addr $domainname; then
  98.         parent=arpa.
  99.     else
  100.         parent=
  101.     fi
  102.  
  103.     # find data file
  104.     while [ "$2" != "" ]; do
  105.         shift
  106.     done
  107.     datafile=$1
  108.  
  109.     # ignore localhost domain stuff
  110.     if [ $domainname = 0.0.127.in-addr.arpa -o $datafile = unixhosts ]; then
  111.         continue
  112.     fi
  113.  
  114.     rm -f log.$domainname.
  115.     doc -w -e $domainname. $parent 2>/dev/null >$TMP.docout
  116.     status=$?
  117.     egrep -v '^(Doc-|DIGERR|Done testing)' <$TMP.docout >$domainname.log
  118.     
  119.     if [ $status -gt $NOTIFYLEVEL ]; then
  120.         notifypersonincharge $domainname $status
  121.     fi
  122.     
  123.     rm -f log.$domainname. $domainname.log
  124. done <$TMP.domains
  125.  
  126. rm -f $TMP*
  127.